package com.fanketly.musicdiary.data.repository

import com.fanketly.musicdiary.data.db.DiaryDao
import com.fanketly.musicdiary.data.model.DiaryModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class DiaryRepo @Inject constructor(
    private val diaryDao: DiaryDao,
) {

    fun getAll(): Flow<List<DiaryModel>> = diaryDao.getAll()

    /**update if insert fails**/
    suspend fun update(diaryModel: DiaryModel) {
        val insert = diaryDao.insert(diaryModel)
        if (insert < 0) diaryDao.update(diaryModel)
    }


}